<?php

class RouterController extends AppController {
	    public $helpers = array('Html', 'Form');
	    var $uses = array('Pagina', 'Album', 'Video', 'MenuItem');
	    
	    public function index() {
	        //$this->set('posts', $this->Post->find('all'));
	    }

	    public function show($id = 6 ){

		 		//Obtengo la pagina de la base.
	    	$pagina = $this->Pagina->findById($id);
		 		
        if (!$pagina) {
            throw new NotFoundException(__('Invalid id'));
        }


        $itemMenu = $this->MenuItem->find('first', array('conditions' 
	 													=> array('MenuItem.pagina_id' => $id)));
       
        if ($itemMenu['MenuItem']['padre'] == 0){
        	$colorearEsteCodigo = $itemMenu['MenuItem']['codigo'];
        }else{
        	$colorearEsteCodigo = $itemMenu['MenuItem']['padre'];
        }

        $this->set('sarasa', $colorearEsteCodigo);

        $this->set('pagina', $pagina);
        $pagina_template = $pagina['Pagina']['template_id'];

        if ($pagina_template == 4){	//Contacto	 	
        	$this->layout = 'template_contenido';    	
	    		$this->render('contacto');
        }elseif ($pagina_template == 2){ // Fotografias
        	$this->set('albums', $this->Album->find('all'));
        	$this->layout = 'template_fotografias';
        	$this->render('fotografias');
        }elseif ($pagina_template == 3) {  // Videos
        	$this->layout = 'template_videos';
        	$this->set('videos', $this->Video->find('all'));
        	$this->render('videos');
        }else{   	
        	$this->layout = 'template_contenido';
	    		$this->render('contenido');
        }
	    }
	 }

?>